<?php
declare (strict_types = 1);

namespace app\controller;

use think\Request;
use think\facade\Db;
class Permission
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        //
		$res = Db::query("select * from permission_admin");
		return json(["code"=>200,"data"=>$res]);
    }
	public function findByRoleId(){
		$p = input("get.");
		$res = Db::query("select * from permission_admin where id in (select permissionId from role_permission_admin where roleId=?)",[$p["id"]]);
		return json(["code"=>200,"data"=>$res]);
	}
    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        //
		$p = input('post.');
		$date = date('Y-m-d H:i:s',time());
		$data = ["name"=>$p["name"],"createTime"=>$date,"updateTime"=>$date];
		Db::name("permission_admin")->insert($data);
		return json(["code"=>200,"msg"=>"操作成功"]);
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        //
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        //
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update()
    {
        //
		$p = input("post.");
		$date = date('Y-m-d H:i:s',time());
		Db::name("permission_admin")->where("id",$p["id"])->update(["name"=>$p["name"],"updateTime"=>$date]);
		return json(["code"=>200,"msg"=>"操作成功"]);
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete()
    {
        //
		$p = input("get.");
		Db::name("permission_admin")->where("id",$p["id"])->delete();
		return json(["code"=>200,"msg"=>"操作成功"]);
    }
}
